package com.wuyoucar.service.impl;

import com.wuyoucar.common.ResultBean;
import com.wuyoucar.entity.TPolicy;
import com.wuyoucar.entity.TReport;
import com.wuyoucar.mapper.PolicyMapper;
import com.wuyoucar.mapper.ReportMapper;
import com.wuyoucar.service.PolicyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class PolicyServiceImpl implements PolicyService {

    @Autowired
    private PolicyMapper policyMapper;
    @Autowired
    private ReportMapper reportMapper;

    //根据订单号查询是否存在
    @Override
    public ResultBean getReportbyNum(Integer policynum,Integer firstid) {
        TPolicy reportbyNum = policyMapper.getReportbyNum(policynum);
        if (reportbyNum != null) {
            //找到了该保单。修改状态为待复审
            int i = reportMapper.updateRecheck(policynum, firstid);
            if (i>0){
                return new ResultBean(0, "初审成功", reportbyNum);
            }else {
                return new ResultBean(500,"初审未通过");
            }

        } else {
            //未找到该保单，驳回
            reportMapper.updateReportAudit(policynum,firstid);
            return new ResultBean(404, "未找到该保单,订单已驳回", reportbyNum);
        }
    }

    //根据保单号查询保单信息
    @Override
    public ResultBean getReportbyNum(Integer policynum) {
        TReport reportByPolicynum = reportMapper.getReportByPolicynum(policynum);
        return new ResultBean(0,"查询成功",reportByPolicynum);
    }


}
